#coding=utf-8
import user_module
'''
getattr(arg1, arg2)
# arg1可以是三种:
        实例, 模块名(不用加双引号),  __import__("模块名")
# arg2可以是:
        "类名", "方法名"
'''
user1 =  user_module.User()
userFunc1_1 = getattr(user1, "showNoArgs")
userFunc1_1()

moduleMeta = __import__("user_module")
UserClass = getattr(moduleMeta, "User") # 获得User类
user2 = UserClass()                     # User类实例化
user2.showNoArgs()

userFunc1_2 = getattr(user2, "showNoArgs")  # 获取showNoArgs方法
userFunc1_2()                               # 方法居然可以不用引用去调用?!


baseFunc1 = getattr(user_module, "funcNoArgs") # 获取funcNoArgs函数
baseFunc1()

baseFunc2 = getattr(user_module, "funcShowArgs") # 获取funcShowArgs函数(带形参)
baseFunc2(123)

baseFunc3 = getattr(user_module, "funcRetArgs")  # 获取funcRetArgs函数(带形参和返回)
retValue = baseFunc3(123)
print(retValue) 
